package poliakov.spring.advertisement.mvc;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;

import poliakov.spring.advertisement.AdvertisementService;
import poliakov.spring.advertisement.pojo.IAdvertisement;
import poliakov.spring.advertisement.pojo.PPAadvertisement;



public class HomeControllerTest {
	
	@Test
	public void shouldDisplayAllAds () {
		List<IAdvertisement> expectedAds = new LinkedList<IAdvertisement>();
		expectedAds.add(new PPAadvertisement());
		expectedAds.add(new PPAadvertisement());
		expectedAds.add(new PPAadvertisement());

		AdvertisementService advertisementService = mock(AdvertisementService.class);
		org.mockito.Mockito.when(advertisementService.getAllAds()).thenReturn(expectedAds);
		
		HomeController controller = new HomeController(advertisementService);
	    HashMap<String, Object> model = new HashMap<String, Object>();
	    String viewName = controller.showHomePage(model);
	    
	    assertEquals("home", viewName);
	    assertSame(expectedAds, model.get("advertisements"));
	    verify(advertisementService).getAllAds();
	}
}
